package io.renren.modules.three;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class ConnectMysql {

    public static void main(String[] args) {
        final String driver = "org.gjt.mm.mysql.Driver";
        final String url = "jdbc:mysql://115.29.19.195:3306/mysql";
        final String user = "root";
        final String password = "123456";
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
            String sql = "SELECT * FROM user";
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                String h = rs.getString(1);
                String u = rs.getString(2);
                System.out.println("host:" + h + ",user:" + u);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
